/** index.js **/
const {
  appInfo,
  urlInfo
} = require("../../config/config.js");
const util = require('../../utils/util.js');
//获取app实例
const app = getApp();

Page({
  data: {
    tableData: [],
    page: 1,
    totalPage: 0,
    loading: false
  },
  onLoad: function() {
    this.getTable(1);
    app.checkLoginStatus(1);
  },
  onShow: function() {
    let that = this;
  },
  getTable: function(page, override) {
    let that = this;
    let userInfo=wx.getStorageSync('userInfo');
    let uid=userInfo.uid;
    let regionid=userInfo.regionid;
    app.post('repair&op=my',{page:1,psize:15,uid:uid,regionid:regionid},function(rel){
     let data=rel.data;
      that.setData({tableData:data.list});
    });
    this.setData({
      loading:true
    }) 
  },

  gotoDetail: function(e) {
   let id= e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/pages/repairList/detail/detail?id=" + id
    })
  },
  gotoAdd:function(){
    let userInfo=wx.getStorageSync('userInfo');
    let regionid=userInfo.regionid;
    app.post('index&op=set',{regionid:regionid},function(rel){
      if(rel.data.isSubmit){
        wx.navigateTo({
          url: "/pages/repair/repair"
        })
      }else{
        app.showInfo(rel.err_msg);
      }
    }); 
  },
  onPullDownRefresh: function() {
    // 上拉刷新
    if (!this.data.loading) {
      this.getTable(1, true).then(() => {
        // 处理完成后，终止下拉刷新
        wx.stopPullDownRefresh()
      })
    }
  },
  onReachBottom: function() {
    // 下拉触底，先判断是否有请求正在进行中
    // 以及检查当前请求页数是不是小于数据总页数，如符合条件，则发送请求
    if (!this.data.loading && this.data.page < this.data.totalPage) {
      this.getTable(this.data.page + 1)
    }
  },
})